package org.joseph.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.joseph.springcloud.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HystrixController {
    @GetMapping("/getuser/{id}")
    @HystrixCommand(fallbackMethod="getUserHystrix")
    public User  getUser(@PathVariable("id") long id){
        return new User().setId(100/id).setUsername("username").setPassword("password").setDb("db?");
    }

    public User  getUserHystrix(@PathVariable("id") long id){
        return new User().setId(0L).setUsername("未知的id");
    }

}
